<template>
    <div class=''>
         <van-nav-bar
            title="收货地址"
            left-text="返回"
            left-arrow
            @click-left="onClickLeft"
        />
        <van-address-edit 
            :area-list="areaList"
            show-postal
            show-delete
            show-set-default
            show-search-result
            :search-result="searchResult"
            :area-columns-placeholder="['请选择', '请选择', '请选择']"
            @save="onSave"
            @delete="onDelete"
            @change-detail="onChangeDetail"
        />
    </div>
</template>

<script>
import area from "../../lib/area"
import { Toast } from 'vant';
// import {getaddress } from "../../api/order";
export default {
    
    components: {},
    data() {
        
        return {
            areaList: area,
            searchResult: [],
            receiver:"",   
            // mobile: "",      
            regions: "", 
            address : "", 
            // idDefault: "",   
            // id: "",
        };
    },
    computed: {},
    watch: {},
    
    methods: {
        onClickLeft(){
            this.$router.push("/user")
        },
         onSave(content) {
            Toast('保存成功');
            console.log(content);
            this.receiver = content.name;
            // this.mobile = content.tel;
            this.regions = `${content.province}-${content.city}-${content.county}`;
            this.address = content.addressDetail;
            // this.idDefault = content.isDefault;
            console.log(this.receiver,this.regions,this.address);
            const data = {receiver:this.receiver,regions:this.regions,address:this.address};
            localStorage.setItem("address", JSON.stringify(data))

          
        },
        onDelete() {
            Toast('删除成功');
        },
        onChangeDetail(val) { 
            if (val) {
                this.searchResult = [
                {
                    name: '黄龙万科中心',
                    address: '杭州市西湖区',
                 },
                ];
            } else {
                this.searchResult = [];
                }
            },
        // async addAddress(){
        //     const result = await addaddress(
        //         {   receiver: this.receiver,
        //             mobile: this.mobile,
        //             regions: this.regions,
        //             address:this.address,
        //             idDefault: this.idDefault}
        //         );
        //     console.log(result);
        //     console.log(result.data.info._id);
        //     this.id = result.data.info._id;
        //     if(result.data.code == "success"){
        //         alert(result.data.message)
                
        //     }
        // },
       
  
    },
    created() {
        // this.addAddress();
    },
    mounted() {
       
    },
    }
</script>
<style scoped>
    
</style>